﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace SL8.SL
{
    /// <summary>
    /// 内容控件基类
    /// </summary>
    public abstract class ContentControlBase : ContentControl, IEventSubscribe, INotifyPropertyChanged
    {
        protected bool IsApplyTemplate { get; set; } 

        private int nWorkingCount = 0;

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// 是否在忙
        /// </summary>
        public bool IsBusy
        {
            get
            {
                return this.nWorkingCount > 0;
            }
            set
            {
                if (value)
                {
                    this.nWorkingCount++;
                }
                else
                {
                    this.nWorkingCount--;
                }

                this.RaisePropertyChanged("IsBusy"); 
            }
        }

        public virtual void SubscribeToTemplatePartEvents()
        { }

        public virtual void UnsubscribeFromTemplatePartEvents()
        { }

        public void RaisePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
